package com.mnkjxy.beauty.view.manager;

import java.util.Observable;
import java.util.Observer;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.mnkjxy.beauty.R;
import com.mnkjxy.beauty.view.FirstView;
import com.mnkjxy.beauty.view.BaiduMapView;
import com.mnkjxy.beauty.view.ThreeView;
import com.mnkjxy.beauty.view.CourseView;

/**
 * 控制底部导航容器
 * 
 * @author Administrator
 * 
 */
public class BottomManager implements Observer, OnClickListener {
	protected static final String TAG = "BottomManager";

	private static BottomManager instrance;
	// 底部四个按钮
	private LinearLayout buttom_one;
	private LinearLayout buttom_two;
	private LinearLayout buttom_three;
	private LinearLayout buttom_four;

	private BottomManager() {
	}

	public static BottomManager getInstrance() {
		if (instrance == null) {
			instrance = new BottomManager();
		}
		return instrance;
	}

	/**
	 * 初始化布局
	 * 
	 * @param context
	 */
	public void init(Activity activity) {
		buttom_one = (LinearLayout) activity.findViewById(R.id.bottom_buttom_one);
		buttom_two = (LinearLayout) activity.findViewById(R.id.bottom_buttom_two);
		buttom_three = (LinearLayout) activity.findViewById(R.id.bottom_buttom_three);
		buttom_four = (LinearLayout) activity.findViewById(R.id.bottom_buttom_four);
		setListener();
	}

	/**
	 * 设置监听
	 */
	private void setListener() {
		buttom_one.setOnClickListener(this);
		buttom_two.setOnClickListener(this);
		buttom_three.setOnClickListener(this);
		buttom_four.setOnClickListener(this);

	}

	private void setClickable() {
		buttom_one.setClickable(true);
		buttom_two.setClickable(true);
		buttom_three.setClickable(true);
		buttom_four.setClickable(true);

	}

	@Override
	public void update(Observable arg0, Object arg1) {

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.bottom_buttom_one:
			setClickable();
			buttom_one.setClickable(false);

			MiddleManage.getInstance().deleteHistry();
			MiddleManage.getInstance().changeView(FirstView.class);
			break;
		case R.id.bottom_buttom_two:
			setClickable();
			buttom_two.setClickable(false);
			MiddleManage.getInstance().deleteHistry();
			MiddleManage.getInstance().changeView(CourseView.class);
			break;
		case R.id.bottom_buttom_three:

			setClickable();
			buttom_three.setClickable(false);
			MiddleManage.getInstance().deleteHistry();
			MiddleManage.getInstance().changeView(ThreeView.class);
			break;
		case R.id.bottom_buttom_four:
			setClickable();
			buttom_four.setClickable(false);
			MiddleManage.getInstance().deleteHistry();
			MiddleManage.getInstance().changeView(BaiduMapView.class);
			break;

		default:
			break;
		}

	}
}
